package cn.edu.scau.cmi.liangzijian.simpleFactoryMethod;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.liangzijian.simpleFactoryMethod.meat.Meat;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;


public class SimpleFactoryMethodUIController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private Button create;

    @FXML
    private ComboBox<String> meatTypeComboBox;

    @FXML
    private TextArea screen;

    private MeatFactory mf = new MeatFactory();
    
    private String meatType = "";
    
    @FXML
    void product(MouseEvent event) {
    	if(!meatType.equals("")) {
    		Meat meat = mf.getMeat(meatType);
    		
    		if(meat != null) {
    			screen.appendText(meat.cook() + "\n");
    		}
    	}
    }

    @FXML
    void initialize() {
        assert create != null : "fx:id=\"create\" was not injected: check your FXML file 'SimpleFactoryMethodUI.fxml'.";
        assert meatTypeComboBox != null : "fx:id=\"meatTypeChoiceBox\" was not injected: check your FXML file 'SimpleFactoryMethodUI.fxml'.";
        assert screen != null : "fx:id=\"screen\" was not injected: check your FXML file 'SimpleFactoryMethodUI.fxml'.";

        meatTypeComboBox.setItems(FXCollections.observableArrayList("beef", "pork", "chicken"));
        meatTypeComboBox.valueProperty().addListener(new ChangeListener() {
			@Override
			public void changed(ObservableValue observable, Object oldValue, Object newValue) {
				meatType = (String)newValue;
			}    	
    	});
    }

}
